import RandomHelper from "../../cfw/tools/RandomHelper";

// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const { ccclass, property } = cc._decorator;

@ccclass
export default class ClickComp extends cc.Component {


    start() {
        this.action();
    }

    action() {
        let r = RandomHelper.random(0, 100)
        if (r >= 50) {
            this.node.opacity = 255;
            cc.tween(this.node).repeat(3, cc.tween(this.node).by(0.3, { x: -5, y: 5 }).by(0.3, { x: 5, y: -5 })).call(() => {
                this.action()
            }).start()
        } else {
            this.node.opacity = 0;
            cc.tween(this.node).to(3, {}).call(() => {
                this.action()
            }).start()
        }

    }
}
